/* ========================================================================== */
/*   ProcessHitController.h    			                                      */
/*   (c) 2012 Team 7 Hogeschool Utrecht ICT TI                                */
/*		Lars Stolwijk, Gerben Boot, Guido van Hienen, Marcel Boelen			  */
/*                                                                            */
/*   When a player gets hit the ProcessHit gets all information and sends	  */ 
/*		it to the log.													      */
/* ========================================================================== */

#ifndef __ProcessHitController
#define __ProcessHitController

#include "pRTOS.h"
#include "Health.h"
#include "Log.h"
#include "SoundController.h"
#include "IRHitEvent.h"

class Health;
class Log;
class SoundController;
class IRHitEvent;

class ProcessHitController : public RTOS::task {
	public:	
		//Constructor
		ProcessHitController(int prio, SoundController * soundController, Log * log):RTOS::task(prio, "ProcessHitControllerTask"), theSoundController(soundController), theLog(log), HealthPlacedFlag(this, "HealthPlacedFlag"), HitFlag(this, "HitFlag"){}
		void registerHealth(Health * health){
			theHealth = health;
		}
		
		void HealthPlaced();
		void Hit();
		void WriteIRResult(IRHitEvent irhe);
		void WriteGameTime(short time);
		
		
	private:
		enum State { WAITING, LOGGING };
		State CurrentState;

		Health * theHealth;
		SoundController * theSoundController;
		Log * theLog;
		
		RTOS::pool<IRHitEvent> IRResultPool;
		RTOS::pool<short> GameTimePool;
		RTOS::mutex GameTimePoolMutex;
		
		//Flags
		RTOS::flag HealthPlacedFlag, HitFlag;
		
		void main();
};

#endif
